package per.dg.keepalive.onepixel

import android.app.Activity
import android.content.ContentValues.TAG
import android.content.Context
import android.util.Log
import java.lang.ref.WeakReference

class ScreenManager {

    companion object{
        var gDefualt : ScreenManager? = null

        fun getInstance(pContext : Context) : ScreenManager {
            if (gDefualt == null) {
                gDefualt = ScreenManager(pContext.getApplicationContext());
            }
            return gDefualt as ScreenManager;
        }
    }

    var mContext : Context

    var mActivityWref : WeakReference<Activity>? = null;





    private constructor(pContext : Context ) {
        this.mContext = pContext;
    }

    fun setActivity(pActivity : Activity ) {
        mActivityWref = WeakReference<Activity>(pActivity);
    }

    fun startActivity() {
        Log.e(TAG, "startActivity: " )
        OnePixelActivity.actionToOnePixelActivity(mContext);
    }

    fun finishActivity() {
        //结束掉SinglePixelActivity
        if (mActivityWref != null) {
            var activity : Activity? = mActivityWref!!.get();
            if (activity != null) {
                activity.finish();
                Log.e(TAG, "finishActivity: " )
            }
        }
    }

}